package bairui.international.config;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.testng.annotations.BeforeClass;

import com.lianjing.sh.project.authority.model.type.Type_Operator;
import com.lianjing.sh.project.config.base.profile.Project_Profile;
import com.lianjing.sh.web.security.common.enums.EncryptionWay;
import com.lianjing.sh.web.security.common.util.Util_Encryption;

import bairui.international.model.domain.jpa.TB_Admin;
import bairui.international.model.status.State_Employee;
import bairui.international.model.type.Type_Gender;
import bairui.international.service.Service_Admin;

@ActiveProfiles(Project_Profile.TestProduct)
public class Config_RootAdmin_TestDeployment extends Config_SecurityBase {

	@Autowired private Service_Admin service_Admin;
	
	@BeforeClass
	protected void beforeClass() throws Exception{
		System.out.println("===============beforeClass====================");
		super.beforeClass();
		/*
		 * 如果没有根用户则创建
		 */
		if(!service_Admin.exists(it->it.username.eq("root"))){
			//
			service_Admin.save(new TB_Admin(new TB_Admin.MustProperties() {
				@Override public String getUsername() {
					return "root";
				}
				@Override public String getPassword() {
					try {
						return Util_Encryption.hashEncryption("123456", new EncryptionWay[]{EncryptionWay.MD5});
					} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
						throw new RuntimeException(e);
					}
				}
				@Override public Boolean getFreezenFlag() {
					return false;
				}
				@Override public Type_Operator getOperatorType() {
					return Type_Operator.RootAdmin;
				}
				@Override
				public String getOperatorName() {
					return "root";
				}
				@Override public String getName() {
					return "root";
				}
				@Override public String getNumber() {
					return "01";
				}
				@Override public String getMobilePhone() {
					return "123456";
				}
				@Override public Type_Gender getGender() {
					return Type_Gender.Man;
				}
				@Override public State_Employee getState() {
					return State_Employee.Working;
				}
				@Override public Boolean getChangeDefaultPasswordFlag() {
					return false;
				}
			}));
		}
//		/*
//		 * 登录根权限雇员
//		 */
//		login();
	}
	
}
